#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from common.const import ReportDBLabel
from informix.comm.const import AllStepEnum
from informix.job_manager import JobManager
from informix.param.restore_param_parse import InformixParseRestoreParam
from informix.service.BaseService import MetaService
from informix.service.restore.restore_factory import RestoreFactory


class RestoreService(MetaService):
    def __init__(self, job_manager: JobManager, param_dict):
        super().__init__(job_manager, param_dict)
        self.param = self.gen_param_obj()
        self.job_manager = job_manager
        self.param_dict = param_dict
        self.restore_manager = RestoreFactory(self.job_manager, self.param_dict, self.param).make_obj()

    def gen_param_obj(self):
        param = InformixParseRestoreParam(self.param_dict, self.job_manager)
        return param

    def get_steps(self):
        pass


@JobManager.register(AllStepEnum.ALLOW_RESTORE)
class AllowRestoreService(RestoreService):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)
        self.need_report = False

    def get_steps(self):
        default_allow = [
            self.restore_manager.init_param,
            self.restore_manager.allow
        ]
        return default_allow


@JobManager.register(AllStepEnum.RESTORE_PREREQUISITE)
class PreRestoreService(RestoreService):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)
        self.need_report = True

    def get_steps(self):
        default_allow = [
            self.restore_manager.init_param,
            self.restore_manager.restore_pre_instance
        ]
        return default_allow


@JobManager.register(AllStepEnum.GENERATOR_SUB_JOB)
class PreRestoreService(RestoreService):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)
        self.need_report = False

    def get_steps(self):
        """
        """
        default_allow = [
            self.restore_manager.init_param,
            self.restore_manager.gen_sub_job
        ]
        return default_allow


@JobManager.register(AllStepEnum.RESTORE)
class PreRestoreService(RestoreService):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)
        self.need_report = True

    def get_steps(self):
        """
        """
        default_allow = [
            self.restore_manager.init_param,
            self.restore_manager.restore
        ]
        return default_allow


@JobManager.register(AllStepEnum.RESTORE_POST)
class PreRestoreService(RestoreService):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)
        self.need_report = True

    def get_steps(self):
        """
        """
        default_allow = [
            self.restore_manager.init_param,
            self.restore_manager.restore_post
        ]
        return default_allow


@JobManager.register(AllStepEnum.RESTORE_GEN_SUB)
class PreRestoreService(RestoreService):
    def __init__(self, job_manager, param_dict):
        super().__init__(job_manager, param_dict)
        self.need_report = False

    def get_steps(self):
        default_allow = [
            self.restore_manager.init_param,
            self.restore_manager.gen_sub_job
        ]
        return default_allow
